import cv2.cv2 as cv
import cv2
import os
import shutil
from tqdm import tqdm 

# images_dir='/home/eziao/datasets/AliYun/suichang_round1_train_210120/'
images_dir = '/home/sunxinyu/Datasets/TianChi/suichang_round1_train_210120'
# save_imgs='/home/eziao/datasets/AliYun/images/'
save_imgs = '/home/sunxinyu/Datasets/TianChi/suichang_jpg_images'
# save_masks='/home/eziao/datasets/AliYun/masks_new/'
save_masks = '/home/sunxinyu/Datasets/TianChi/suichang_masks'

if not os.path.exists(save_imgs):os.makedirs(save_imgs)
if not os.path.exists(save_masks):os.makedirs(save_masks)

'''
tif_list = [x for x in os.listdir(images_dir)]   # 获取目录中所有tif格式图像列表
for num, name in tqdm(enumerate(tif_list), total=len(tif_list)):      # 遍历列表
    if name.endswith(".tif"):
        img = cv.imread(os.path.join(images_dir, name),-1)       #  读取列表中的tif图像
        cv.imwrite(os.path.join(save_imgs,name.split('.')[0]+".jpg"),img)    # tif 格式转 jpg 
    else:
        img =cv.imread(os.path.join(images_dir, name),cv2.IMREAD_GRAYSCALE)
        img = img-1
        cv2.imwrite(os.path.join(save_masks, name),img)
        #shutil.copy(os.path.join(images_dir, name),os.path.join(save_masks,name))
'''

# test_dir='/home/eziao/datasets/AliYun/suichang_round1_train_210120/'
test_dir = '/home/sunxinyu/Datasets/TianChi/suichang_round1_test_partA_210120'
# save_test_dir='/home/eziao/datasets/AliYun/test_jpg'
save_test_dir = '/home/sunxinyu/Datasets/TianChi/suichang_jpg_test'
if not os.path.exists(save_test_dir):os.makedirs(save_test_dir)
for name in tqdm(os.listdir(test_dir)):
    img = cv.imread(os.path.join(test_dir, name),-1)       # 
    cv.imwrite(os.path.join(save_test_dir, name.split('.')[0]+".jpg"),img)    # tif 格式转 jpg 